﻿using ConfExpert.Forms.Base;
using DevExpress.Utils;
using DevExpress.XtraGrid.Views.Grid;
using DevTeam;
using System;
using System.Drawing;

namespace ConfExpert.Forms.Espresso
{
    public partial class FiyatYeni : XForm
    {
        int ver = 4;
        public FiyatYeni(int ver)
        {
            InitializeComponent();
            this.ver = ver;
        }

        bool EstiCemal;
        private void FiyatYeni_Load(object sender, EventArgs e)
        {
            
            EstiCemal =ytk(116);
            gridView1.Init("GetEspresso", ver);


            gridView1.SetCaptions("Width:Width (±%3)", "Weight:Weight (±%3)");

            gridView1.Columns["Width"].DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
            gridView1.Columns["Width"].DisplayFormat.FormatString = "#,###.## cm'.'";

            gridView1.Columns["Weight"].DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
            gridView1.Columns["Weight"].DisplayFormat.FormatString = "#,###.## gr'/'m2";

            foreach (string str in "GomlekHesaplama,KumasSatisListe,KumasSatisGercek,KumasSatisOzelIskonto".Split(','))
            {
                gridView1.Columns[str].DisplayFormat.FormatType = DevExpress.Utils.FormatType.Numeric;
                gridView1.Columns[str].DisplayFormat.FormatString = (ver < 4 ? "€" : "$") + " #,###.00";
            }

            gridView1.PaintAppearance.EvenRow.BackColor = Color.FromArgb(242, 220, 219);
            gridView1.PaintAppearance.HorzLine.BackColor = Color.FromArgb(218, 150, 150);

            gridView1.RowCellStyle += new DevExpress.XtraGrid.Views.Grid.RowCellStyleEventHandler(gridView1_RowCellStyle);

            //gridView1.GroupFormat = "[#image]{1}"; //"{0}: [#image]{1} {2}".

            bbiKaydet.ItemClick += bbiKaydet_ItemClick;

            //gridView1.Columns["Booklet"].ColumnEdit = RI(Rp.GrupESP);
            gridView1.OptionsBehavior.Editable = EstiCemal;
            gridView1.AddSummary();

            //gridView1.FocusedRowChanged += new DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventHandler(gridView1_FocusedRowChanged);
            //gridView1.ShowFindPanel();

            //gridView1.CustomColumnDisplayText += new CustomColumnDisplayTextEventHandler(gridView1_CustomColumnDisplayText);


            //gridView1.OptionsView.AllowCellMerge = true;
            //gridView1.CellMerge += gridView1_CellMerge;
            gridView1.BestFitColumns();


            //gridView1.CustomColumnDisplayText+=new CustomColumnDisplayTextEventHandler(gridView1_CustomColumnDisplayText);
        }

        void gridView1_CellMerge(object sender, DevExpress.XtraGrid.Views.Grid.CellMergeEventArgs e)
        {
            GridView view = sender as GridView;
            e.Merge = view.GetRowCellDisplayText(e.RowHandle1, e.Column) == view.GetRowCellDisplayText(e.RowHandle2, e.Column) &&
                (e.Column.FieldName.Contains("Booklet") || e.Column.FieldName.Contains("GrupESPId"));
            e.Handled = true;
        }


        void bbiKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            if (EstiCemal)
            {
                gridView1.EndEditing();
                gridView1.Update("", "EspMaliyetYeni" + (ver < 4 ? string.Empty : "2"));
            }

            gridView1.RefreshDataSource("GetEspresso", ver);
        }

        void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            switch (e.Column.FieldName)
            {
                case "KaliteId":
                    e.Appearance.Font = new Font(AppearanceObject.DefaultFont, FontStyle.Bold);
                    break;
            }
        }

    }
}
